package lp.polimi.treefinder;


import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.os.Bundle;
import android.os.Environment;

public class MediaMountedActivity extends Activity {

	/**
	 * Check if the external storage is mounted. If not, closes the app, as
	 * it uses the external storage to save and retrieve leaves data.
	 */
	protected void checkMediaMounted () {
		if (!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
			AlertDialog.Builder alertDialog = new AlertDialog.Builder(this);
			alertDialog.setTitle(getResources().getString(R.string.error));
			alertDialog.setMessage(getResources().getString(R.string.file_error));
			alertDialog.setPositiveButton(R.string.ok, new OnClickListener() {
				
				@Override
				public void onClick(DialogInterface dialog, int which) {
					finish();
				}
			});
			alertDialog.show();
		}
	}
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		checkMediaMounted();
	}
	
	@Override
	protected void onResume() {
		super.onResume();
		checkMediaMounted();
	}
}
